<?php
/**
 * 个人中心控制器
 * Date: 2025/09/08
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\BaseController;
use App\Services\Admin\MyService;
use Illuminate\Http\Request;

class MyController extends BaseController
{
    /**
     * 我的信息
     * @date 2025/09/08
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function info(Request $request)
    {
        return (new MyService())->info($request->adminInfo['id']);
    }

    /**
     * 修改信息
     * @date 2025/09/08
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function update(Request $request)
    {
        $params = $this->validate($request, [
            'avatar' => 'sometimes',
            'name' => 'sometimes',
            'email' => 'sometimes',
            'phone' => 'sometimes'
        ]);

        $params['id'] = $request->adminInfo['id'];
        return (new MyService())->update($params);
    }

    /**
     * 修改密码
     * @date 2025/09/08
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function password(Request $request)
    {
        $params = $this->validate($request, [
            'password' => 'required',
            'new_password' => 'required',
        ], [
            'password.required' => '当前密码不能为空',
            'new_password.required' => '新密码不能为空',
        ]);

        $params['id'] = $request->adminInfo['id'];
        $params['old_password'] = $request->adminInfo['password'];
        return (new MyService())->password($params);
    }
}
